#include "uart.h"



void Uart4_Init(uint32_t baud)
{
	GPIO_InitTypeDef GPIO_InitStruct;
	USART_InitTypeDef USART_InitStruct;
	
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4,ENABLE);
	
	GPIO_InitStruct.GPIO_Mode 	= GPIO_Mode_AF_PP;
	GPIO_InitStruct.GPIO_Pin		= GPIO_Pin_10;
	GPIO_InitStruct.GPIO_Speed	= GPIO_Speed_50MHz;
	GPIO_Init(GPIOC,&GPIO_InitStruct);
	GPIO_InitStruct.GPIO_Mode 	= GPIO_Mode_IN_FLOATING;
	GPIO_InitStruct.GPIO_Pin		= GPIO_Pin_11;
	GPIO_Init(GPIOC,&GPIO_InitStruct);
	
	USART_InitStruct.USART_BaudRate							= baud;
	USART_InitStruct.USART_HardwareFlowControl	= USART_HardwareFlowControl_None;
	USART_InitStruct.USART_Mode									= USART_Mode_Rx|USART_Mode_Tx;
	USART_InitStruct.USART_Parity								= USART_Parity_No;
	USART_InitStruct.USART_StopBits							= USART_StopBits_1;
	USART_InitStruct.USART_WordLength						= USART_WordLength_8b;
	
	USART_Init(UART4,&USART_InitStruct);
	USART_Cmd(UART4,ENABLE);

}



void Send_Byte(uint8_t byte)
{
	while(USART_GetFlagStatus(UART4,USART_FLAG_TC) == RESET);
	USART_SendData(UART4,(uint8_t)byte);
}

void SendStr(char *buf)
{
	while(*buf != '\0')
	{
		Send_Byte(*buf++);
	}
}


